package com.gt.acc

import com.gt.SCUtil
import org.apache.spark.SparkContext
import org.apache.spark.rdd.RDD

object Spark_acc_03 {

  def main(args: Array[String]): Unit = {
    val sc: SparkContext = SCUtil.createLocalSc()
    val rdd: RDD[String] = sc.makeRDD(List("hello", "spark", "scala", "spark", "scala"))

    val myAccumulator = new MyAccumulator()
    sc.register(myAccumulator, "myAccumulator")

    rdd.foreach(
      str =>{
        myAccumulator.add(str)
      }
    )

    println(myAccumulator.value)


    sc.stop()

  }

}
